﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NP.Model;

namespace NP.BL
{
    public class UnitsInStock
    {
        public UnitsInStockViewModel[] GetStock()
        {
            using (var db = new NorthwindDataClassesDataContext())
            {
                var stock = db.Products.ToArray()
                    .Select(n => new UnitsInStockViewModel
                    {
                        ProductID = n.ProductID,
                        ProductName = n.ProductName,
                        SupplierID = (int)n.SupplierID,
                        SupplierName = n.Supplier.CompanyName,
                        UnitsInStock = (int)n.UnitsInStock
                    }).OrderBy(n => n.ProductName).ToArray();

                return stock;
            }
        }
    }
}
